/*
  Modified from:
* http://blog.stuartlewis.com/2011/02/12/scrolling-text-with-an-arduino-and-nokia-5110-screen/
* http://www.arduino.cc/playground/Code/PCD8544
  modified by pyavinci@gmail.com
  + Separated header file to NokiaLCD.h for clarity
  + Reorder utility functions 
  + Pin identification
*/
// The pins to use on the arduino
#define PIN_SCLK  3    // NKLCD-7 --> D3 
#define PIN_SDIN  4    // NKLCD-6 --> D4
#define PIN_DC    5    // NKLCD-5 --> D5    
#define PIN_RESET 6    // NKLCD-4 --> D6
#define PIN_SCE   7    // NKLCD-3 --> D7
// NKLCD-8 -->Backlight
// NKLCD-2 -->GND
// NKLCD-1 -->V3.3 !!!BE CAREFUL
#include "NokiaLCD.h"  // This must be here!! do not move to top
// 6 lines (0 to 5)
// 83 H_dots (0 to 82)
#include <SHT1x.h>    // For Temp-Humi module
/* FOR SHT1x Digital Temperature and Humidity 
  Connectors (SCK, DATA) facing the board
  SCK S=>10, Vcc, Gnd
  DATA D=>9, Vcc, Gnd
*/
#define DATA_PIN  9   // DATA
#define CLK_PIN 10   // SCK
SHT1x sht1x(DATA_PIN, CLK_PIN);

void setup(void)
{
  LcdInitialise();
  LcdClear();
 
  gotoXY(0,0); // ln=0
  LcdString("CRMA SensNet");
  gotoXY(0,1); // ln=1
  LcdString("by pyavinci");
}
 
void loop(void)
{
//  char Millis[20];
//  sprintf(Millis,"%u",millis());
  char TempC[20], TempF[20], Humid[20];
  float temp_c;
//  float temp_f;
  float humidity;

  // Read values from the sensor SHT1X
  temp_c = sht1x.readTemperatureC();
  int temp_c_dec=(temp_c-(int)temp_c)*100;
//  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();
  int humi_dec = (humidity-(int)humidity)*100;
  // NOTE!! No direct support for sprintf FLOAT
  // so we simply do the manual converstion here.
  sprintf(TempC,"%0d.%2d",(int)temp_c, temp_c_dec );
  sprintf(Humid,"%0d.%2d",(int)humidity, humi_dec );
//  gotoXY(0,2); LcdString(Millis);
  gotoXY(0,3); LcdString("TempC:");
  gotoXY(42,3); LcdString(TempC);
  gotoXY(0,4); LcdString("Humid:");
  gotoXY(42,4); LcdString(Humid);
  gotoXY(0,5);
  Scroll("Sensor Network Project by CRMA Research Team");
  delay(100);
}

